﻿using UnityEngine;
using System.Collections;

public class camara : MonoBehaviour {

	Transform target;
	public Transform player; 

	public Vector3 offset;
	public Vector2 xLim;
	public Vector2 yLim;

	Vector3 targetPosition; 

	// Use this for initialization
	void Start () {

		target = player;
	
	}
	
	// Update is called once per frame
//	void Update () {
//	
//	}

	void Update()
	{
		targetPosition = target.position + offset + Vector3.right*Mathf.Sign(target.forward.x)*3;
		targetPosition.x = Mathf.Lerp (transform.position.x,targetPosition.x,Time.deltaTime*4);
		targetPosition.y = Mathf.Lerp (transform.position.y,targetPosition.y,Time.deltaTime*2);
		targetPosition.z = Mathf.Lerp (transform.position.z,targetPosition.z,Time.deltaTime);

		if(targetPosition.x < xLim.x || targetPosition.x > xLim.y)
		{
			targetPosition.x = transform.position.x;
		}
		if(targetPosition.y < yLim.x || targetPosition.y > yLim.y)
		{
			targetPosition.y = transform.position.y;

		}
		transform.position = targetPosition;
	}
}
